/*
 * sms_appender.cpp
 *
 *  Created on: 2008-12-2
 *      Author: fanliangliang
 */

#include "sms_appender.h"

using namespace toxic;

SmsAppender::SmsAppender()
:_level()
,_service()
,_message() {

}

SmsAppender::~SmsAppender() {

}

void SmsAppender::doAppend(const Log::Event& e) {
	if (e.level == _level) {
		_message.setText(e.message);
		if (!_service.send(_message)) {
			// TODO send sms message failed
		}
	}
}

void SmsAppender::setWarnLevel(Log::Level level) {
	_level = level;
}

void SmsAppender::setMessageService(const MessageService& service) {
	_service = service;
}

void SmsAppender::addPhoneNumber(const string& phoneNumber) {
	_message.addPhoneNumber(phoneNumber);
}

void SmsAppender::addPhoneNumber(const vector<string>& phoneNumbers) {
	foreach (const string& s, phoneNumbers) {
		_message.addPhoneNumber(s);
	}
}
